package synchronizedTest;

import java.util.HashMap;
import java.util.Map;

public class Foo {

    private static final Map map = new HashMap();
    public synchronized void  m1(){
        try {
            System.out.println(Thread.currentThread().getName() +" ******执行m1开始");
            Thread.sleep(3000);
            System.out.println(Thread.currentThread().getName() +" ******执行m1完成");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public synchronized void  m2(){
        try {
            System.out.println(Thread.currentThread().getName() +" ******执行m2开始");
            Thread.sleep(3000);
            System.out.println(Thread.currentThread().getName() +" ******执行m2完成");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void  m3(){
        try {
            System.out.println(Foo.class);
            synchronized(Foo.class){
                System.out.println(Thread.currentThread().getName() + " ******执行m3开始");
                Thread.sleep(3000);
                System.out.println(Thread.currentThread().getName() + " ******执行m3完成");
            }
            } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void  m4(){

        try {
            System.out.println(Foo.class);
            synchronized(Foo.class){
            System.out.println(Thread.currentThread().getName() +" ******执行m4开始");
            Thread.sleep(3000);
            System.out.println(Thread.currentThread().getName() +" ******执行m4完成");
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void  m5(){
        try {
            System.out.println(Foo.map);
            synchronized(Foo.map){
                System.out.println(Thread.currentThread().getName() + " ******执行m5开始");
                Thread.sleep(3000);
                System.out.println(Thread.currentThread().getName() + " ******执行m5完成");
            }
            } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void  m6(){
        try {
            System.out.println(Foo.map);
            synchronized(Foo.map){
            System.out.println(Thread.currentThread().getName() +" ******执行m6开始");
            Thread.sleep(3000);
            System.out.println(Thread.currentThread().getName() +" ******执行m6完成");
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
